package com.acquisition.common.entity;

import com.acquisition.common.enums.ResultCode;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import java.util.List;

/**
 * @Author Jay Chou
 * @Description 公共响应类
 * @Date 2023-04-12 11:25
 **/
public class BaseResponse<T>{
	
	private Integer code;

	private String message;

	private T data;

	public BaseResponse() {
		super();
	}
	
	public BaseResponse(Integer code, String message) {
		this.setCode(code);
		this.setMessage(message);
	}

	public BaseResponse(Integer code, String message, T data) {
		this.setCode(code);
		this.setMessage(message);
		this.setData(data);
	}

	public BaseResponse(ResultCode resultCode) {
		this.setCode(resultCode.getCode());
		this.setMessage(resultCode.getMessage());
		this.setData(null);
	}

	public BaseResponse(ResultCode resultCode , T data) {
		this.setCode(resultCode.getCode());
		this.setMessage(resultCode.getMessage());
		this.setData(data);
	}
	
	public BaseResponse(ResultCode resultCode,String message, T data) {
		this.setCode(resultCode.getCode());
		this.setMessage(message);
		this.setData(data);
	}

	public static <T> BaseResponse<PageInfo<T>> data(List<T> list) {
		return new BaseResponse<>(ResultCode.SUCCESS, new PageInfo<>(list));
	}

	public static <T> BaseResponse<T> success() {
		return new BaseResponse<>(ResultCode.SUCCESS, null);
	}

	public static <T> BaseResponse<T> success(String message) {
		return new BaseResponse<>(ResultCode.SUCCESS, message, null);
	}

	public static <T> BaseResponse<T> success(T data) {
		return new BaseResponse<>(ResultCode.SUCCESS, data);
	}

	public static <T> BaseResponse<T> success(String message, T data) {
		return new BaseResponse<>(ResultCode.SUCCESS, message, data);
	}

	public static <T> BaseResponse<T> fail() {
		return new BaseResponse<>(ResultCode.Fail, null);
	}

	public static <T> BaseResponse<T> fail(String message) {
		return new BaseResponse<>(ResultCode.Fail, message, null);
	}

	public static <T> BaseResponse<T> fail(T data) {
		return new BaseResponse<>(ResultCode.Fail, data);
	}

	public static <T> BaseResponse<T> fail(String message, T data) {
		return new BaseResponse<>(ResultCode.Fail, message, data);
	}

	public static <T> BaseResponse<T> error() {
		return new BaseResponse<>(ResultCode.ERROR, null);
	}

	public static <T> BaseResponse<T> error(String message) {
		return new BaseResponse<>(ResultCode.ERROR, message, null);
	}

	public static <T> BaseResponse<T> error(T data) {
		return new BaseResponse<>(ResultCode.ERROR, data);
	}

	public static <T> BaseResponse<T> error(String message, T data) {
		return new BaseResponse<>(ResultCode.ERROR, message, data);
	}

	@Override
	public String toString() {
		return "BaseResponse [code=" + code + ", message=" + message + ", data=" + data + "]";
	}

	public String toJSONString() {
		return JSON.toJSONString(this);
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
